package pl.prv.polanie.client.panels.lists;

import pl.prv.polanie.client.dialogs.CreateSubjectTypeDialog;
import pl.prv.polanie.client.dto.CSSubjectTypeDTO;
import pl.prv.polanie.client.dto.CSVSubjectTypeDTO;
import pl.prv.polanie.client.model.Cache;
import pl.prv.polanie.client.model.ViewDataProvider;
import pl.prv.polanie.client.widgets.table.TableSubjectTypes;

import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.Widget;

public class SubjectTypesList extends ObjectsList {

	TableSubjectTypes tableSubjectTypes= new TableSubjectTypes(this);
	
	public SubjectTypesList() {
		
		CSSubjectTypeDTO[] ls = Cache.getAllSubjectTypes();
		
		add(tableSubjectTypes);
		
		
		for (int i = 0; i < ls.length; i++) {
			
			CSSubjectTypeDTO cs = ls[i];
			CSVSubjectTypeDTO csv = ViewDataProvider.getCSVSubjectType(cs);
			
			tableSubjectTypes.addRow(cs, csv);
		}
		
		
		addRecordButton.addClickListener(new ClickListener(){
			public void onClick(Widget sender) {
				CreateSubjectTypeDialog cstd = new CreateSubjectTypeDialog(SubjectTypesList.this, null); 
				cstd.center();
			}
		});
		
		removeSelectedRecordButton.addClickListener(new ClickListener() {
			public void onClick(Widget sender) {
				tableSubjectTypes.removeSelectedSubjectTypeFromTable();
			}
		});
		
		setupButtons();
	}

	
	public void addCSSubjectType(CSSubjectTypeDTO csSubjectType) {
		tableSubjectTypes.saveOrUpdateSubjectTypeInTable(csSubjectType);
	}
	
	public void removeSelectdCSLecturer() {
		tableSubjectTypes.removeSelectedSubjectTypeFromTable();
	}
	
}
